<?php 
namespace Home\Controller;
use OT\DataDictionary;
class DetailController extends HomeController {
    public function index(){
    	$id=I('get.id');
        $list = M('goods')->where(array('id'=>$id))->select();
        $picture =M('picture')->getField('id,path');
        $price = M('price')->where(array('gid'=>$id))->order('mprice')->limit(1)->find();
        $cate=get_parent_category($list[0]['cid']);
        $attr= M('attr')->where(array('gid'=>$id))->select();     
        $attrval= M('attrval')->where(array('gid'=>$id))->select();
        $count=M('order')->count();
        // var_dump($price);     
        
        foreach ($attr as $k => $av) {
             foreach ($attrval as $kk => $vv) {
             	if ($av['id']==$vv['kid']) {
             		$attr[$k]['val'][]=$vv;
             	}
             }
            

             }
          // var_dump($attr[0]['val']); 
        // var_dump($price);
        // var_dump($list);
        foreach ($list as $k => $v) {
        	$list[$k]['pic']=$picture[$list[$k]['icon']];
        	// $list[$k]['cate']=$cate[$list[$k]['cid']];
        	$list[$k]['cate']=get_parent_category($list[$k]['cid']); 
        	
        }
       
        $this->assign('list',$list);
        $this->assign('cate',$cate);
        $this->assign('attr',$attr);
        $this->assign('price',$price);
        $this->assign('count',$count);
        $this->assign('page',D('goods')->page);//分页                
        $this->display();
    } 
    public function ajax(){
    	$map['gid']=I('post.gid');
        $map['attrvalid']=implode(',',I('post.attr'));
        // var_dump($map);
        $res=M('price')->where($map)->find();
       // var_dump($res);
        if ($res) {
            
            $date['mprice']=$res['mprice'];
            $date['num']=$res['num'];
            $date['status']=1;
            $date['msg']='success';
        }else{
            $date['mprice']='';
            $date['num']='';
            $date['status']=0;
            $date['msg']='没有下一级'; 
        }
        
         $this->ajaxReturn($date);
    }
   

}